<template>
	<cl-crud ref="Crud">
		<cl-row>
			<!-- 刷新按钮 -->
			<cl-refresh-btn />
			<!-- 新增按钮 -->
			<cl-add-btn />
			<!-- 删除按钮 -->
			<cl-multi-delete-btn />
			<cl-flex1 />
			<!-- 条件搜索 -->
			<cl-search ref="Search" />
		</cl-row>

		<cl-row>
			<!-- 数据表格 -->
			<cl-table ref="Table" />
		</cl-row>

		<cl-row>
			<cl-flex1 />
			<!-- 分页控件 -->
			<cl-pagination />
		</cl-row>

		<!-- 新增、编辑 -->
		<cl-upsert ref="Upsert" />
	</cl-crud>
</template>

<script lang="ts" setup>
defineOptions({
	name: "supplier-evaluation",
});

import { useCrud, useTable, useUpsert, useSearch } from "@cool-vue/crud";
import { useCool } from "/@/cool";
import { useI18n } from "vue-i18n";
import { reactive } from "vue";
import SupplierSelect from "/$/supplier/components/supplier-select.vue";

const { service } = useCool();
const { t } = useI18n();

// 选项
const options = reactive({
	qualityScore: [
		{ label: t("1"), value: 0 },
		{ label: t("2"), value: 1 },
		{ label: t("3"), value: 2 },
		{ label: t("4"), value: 3 },
		{ label: t("5"), value: 4 },
	],
	deliveryScore: [
		{ label: t("1"), value: 0 },
		{ label: t("2"), value: 1 },
		{ label: t("3"), value: 2 },
		{ label: t("4"), value: 3 },
		{ label: t("5"), value: 4 },
	],
	serviceScore: [
		{ label: t("1"), value: 0 },
		{ label: t("2"), value: 1 },
		{ label: t("3"), value: 2 },
		{ label: t("4"), value: 3 },
		{ label: t("5"), value: 4 },
	],
});

// cl-upsert
const Upsert = useUpsert({
	items: [
		{
			label: t("选择供应商"),
			prop: "supplierId",
			component: { vm: SupplierSelect },
			span: 12,
			required: true,
		},
		{
			label: t("质量评分"),
			prop: "qualityScore",
			component: {
				name: "cl-select",
				props: { options: options.qualityScore },
			},
			value: 4,
			span: 12,
			required: true,
		},
		{
			label: t("交付评分"),
			prop: "deliveryScore",
			component: {
				name: "cl-select",
				props: { options: options.deliveryScore },
			},
			value: 4,
			span: 12,
			required: true,
		},
		{
			label: t("服务评分"),
			prop: "serviceScore",
			component: {
				name: "cl-select",
				props: { options: options.serviceScore },
			},
			value: 4,
			span: 12,
			required: true,
		},
		{
			label: t("综合评分"),
			prop: "overallScore",
			component: { name: "el-rate" },
			span: 12,
			required: true,
		},
		{
			label: t("评价内容"),
			prop: "content",
			component: { name: "cl-editor-wang" },
		},
		{
			label: t("评价时间"),
			prop: "evaluationDate",
			component: {
				name: "el-date-picker",
				props: { type: "date", valueFormat: "YYYY-MM-DD" },
			},
			span: 12,
			required: true,
		},
	],
});

// cl-table
const Table = useTable({
	columns: [
		{ type: "selection" },
		{ label: t("联系电话"), prop: "contactPhone", minWidth: 140 },
		{ label: t("联系人"), prop: "contactPerson", minWidth: 140 },
		{ label: t("名称"), prop: "supplierName", minWidth: 140 },
		{
			label: t("质量评分"),
			prop: "qualityScore",
			minWidth: 150,
			component: { name: "el-rate", props: { disabled: true } },
			dict: options.qualityScore,
		},
		{
			label: t("交付评分"),
			prop: "deliveryScore",
			minWidth: 150,
			component: { name: "el-rate", props: { disabled: true } },
			dict: options.deliveryScore,
		},
		{
			label: t("服务评分"),
			prop: "serviceScore",
			minWidth: 150,
			component: { name: "el-rate", props: { disabled: true } },
			dict: options.serviceScore,
		},
		{
			label: t("综合评分"),
			prop: "overallScore",
			minWidth: 150,
			component: { name: "el-rate", props: { disabled: true } },
		},
		{
			label: t("评价内容"),
			prop: "content",
			minWidth: 120,
			component: { name: "cl-editor-preview", props: { name: "wang" } },
		},
		{
			label: t("评价时间"),
			prop: "evaluationDate",
			minWidth: 140,
			sortable: "custom",
			component: {
				name: "cl-date-text",
				props: { format: "YYYY-MM-DD" },
			},
		},
		{
			label: t("创建时间"),
			prop: "createTime",
			minWidth: 170,
			sortable: "desc",
			component: { name: "cl-date-text" },
		},
		{
			label: t("更新时间"),
			prop: "updateTime",
			minWidth: 170,
			sortable: "custom",
			component: { name: "cl-date-text" },
		},
		{ type: "op", buttons: ["edit", "delete"] },
	],
});

// cl-search
const Search = useSearch();

// cl-crud
const Crud = useCrud(
	{
		service: service.supplier.evaluation,
	},
	(app) => {
		app.refresh();
	},
);

// 刷新
function refresh(params?: any) {
	Crud.value?.refresh(params);
}
</script>
